﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace RecipeML.Test
{
	/// <summary>
	/// This test class should contain all the tests necessary to prove
	/// that the Recipe class is functioning well.
	/// </summary>
	[TestClass]
	public class MenuTest
	{
		public MenuTest()
		{
			//
			// TODO: Add constructor logic here
			//
		}

		private TestContext testContextInstance;

		/// <summary>
		///Gets or sets the test context which provides
		///information about and functionality for the current test run.
		///</summary>
		public TestContext TestContext
		{
			get
			{
				return testContextInstance;
			}
			set
			{
				testContextInstance = value;
			}
		}

		#region Additional test attributes
		//
		// You can use the following additional attributes as you write your tests:
		//
		// Use ClassInitialize to run code before running the first test in the class
		// [ClassInitialize()]
		// public static void MyClassInitialize(TestContext testContext) { }
		//
		// Use ClassCleanup to run code after all tests in a class have run
		// [ClassCleanup()]
		// public static void MyClassCleanup() { }
		//
		// Use TestInitialize to run code before running each test 
		// [TestInitialize()]
		// public void MyTestInitialize() { }
		//
		// Use TestCleanup to run code after each test has run
		// [TestCleanup()]
		// public void MyTestCleanup() { }
		//
		#endregion

		#region general tests

		[TestMethod]
		[ExpectedException(typeof(Exception))]
		public void LoadFromZip_WhenCalledWithNonexistentFile_ThrowsException()
		{
			var m = new Menu();
			m.LoadFromFile(@"..\..\..\RecipeML.Test\TestData\thisFileDoesNotExist.zip");
		}

		#endregion general tests

		#region Menu1


		[TestMethod]
		public void LoadFromZip_WhenCalledWithValidFile_LoadsAllMenus()
		{
			var m = new Menu();
			m.LoadFromFile(@"..\..\..\RecipeML.Test\TestData\Menu1.xml");
			Assert.AreEqual(m.Meals.Count(), 7);
		}

		[TestMethod]
		public void ToString_WhenCalled_ReturnsValidString()
		{
			var m = new Menu();
			m.LoadFromFile(@"..\..\..\RecipeML.Test\TestData\Menu1.xml");
			var s = m.ToString();
			Assert.IsFalse(string.IsNullOrEmpty(s));
		}

		[TestMethod]
		public void ShoppingList_WhenCalled_ReturnsListOfIngredients()
		{
			var m = new Menu();
			m.LoadFromFile(@"..\..\..\RecipeML.Test\TestData\Menu1.xml");
			var s = m.GetShoppingList();
			Assert.IsTrue(s.Count > 0);
		}

		[TestMethod]
		public void ShoppingList_WhenCalledWithEmptyMenu_ReturnsEmptyListOfIngredients()
		{
			var m = new Menu();
			var s = m.GetShoppingList();
			Assert.IsTrue(s.Count == 0);
		}

		[TestMethod]
		public void ShoppingList_WhenCalled_ReturnsListOfAllIngredients()
		{
			//implement logic to test that the number of ingredients
			//returned is the proper number depending on the menu
			//that was loaded.
		}


		[TestMethod]
		public void ToXML_Menu1_ReturnValueCanBeLoaded()
		{
			var originalObj = new Menu();
			originalObj.LoadFromFile(@"..\..\..\RecipeML.Test\TestData\Menu1.xml");
			var newObj = new Menu();
			newObj.LoadFromString(originalObj.ToXML());
			Assert.AreEqual(originalObj.Title, newObj.Title);
			Assert.AreEqual(originalObj.Meals.Count(), newObj.Meals.Count());
		}

		#endregion Menu1

	}
}
